/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bancodedados3d;

import com.sun.j3d.utils.geometry.Text2D;
import java.awt.Font;
import javax.media.j3d.*;
import javax.vecmath.Color3f;
import javax.vecmath.Vector3f;

/**
 * Title: Label3D
 * Description: Places a Text2D in a scene, allows the text to be seen from the back
 * Copyright:    Copyright (c) 2001
 * Company:      Meissner Software Development, LLC
 * @author Karl Meissner
 * @version 1.0

 */
public class Texto3D extends TransformGroup {

    Text2D texto2D;
    private String texto;
    private String Fonte;
    private int tamanho;
    private Color3f cor;
    private int arte;
    private float x;
    private float y;
    private float z;

    public Texto3D(float x, float y, float z, String msg) {
        super();

        setTexto(msg);
//        "Helvetica"
        setFonte("Georgia");
        setTamanho(18);
        setCor(new Color3f(1.0f, 1.0f, 1.0f));
        setArte(Font.HANGING_BASELINE);
        setX(x);
        setY(y);
        setZ(z);

        // place it in the scene graph
        Transform3D offset = new Transform3D();
        offset.setTranslation(new Vector3f(getX(), getY(), getZ()));
        this.setTransform(offset);

        // face it in the scene graph
        Transform3D rotation = new Transform3D();
        TransformGroup rotation_group = new TransformGroup(rotation);
        this.addChild(rotation_group);

        // make a texture mapped polygon
        texto2D = new Text2D(getTexto(), getCor(), getFonte(), getTamanho(), getArte());


        // set it to draw both the front and back of the poly
        PolygonAttributes msg_attributes = new PolygonAttributes();
        msg_attributes.setCullFace(PolygonAttributes.CULL_NONE);
        msg_attributes.setBackFaceNormalFlip(true);
        texto2D.getAppearance().setPolygonAttributes(msg_attributes);

        // attach it
        rotation_group.addChild(texto2D);
    }

    public Texto3D(String msg) {
        setTexto(msg);
//        "Helvetica"
        setFonte("Georgia");
        setTamanho(18);
        setCor(new Color3f(1.0f, 1.0f, 1.0f));
        setArte(Font.HANGING_BASELINE);

        // face it in the scene graph
        Transform3D rotation = new Transform3D();
        TransformGroup rotation_group = new TransformGroup(rotation);
        this.addChild(rotation_group);

        // make a texture mapped polygon
        texto2D = new Text2D(getTexto(), getCor(), getFonte(), getTamanho(), getArte());

        // set it to draw both the front and back of the poly
        PolygonAttributes msg_attributes = new PolygonAttributes();
        msg_attributes.setCullFace(PolygonAttributes.CULL_NONE);
        msg_attributes.setBackFaceNormalFlip(true);
        texto2D.getAppearance().setPolygonAttributes(msg_attributes);

        // attach it
        rotation_group.addChild(texto2D);
    }

    public void setPos(float x, float y, float z) {
        setX(x);
        setY(y);
        setZ(z);

//        this.removeAllChildren();

        Transform3D offset = new Transform3D();
        offset.setTranslation(new Vector3f(getX(), getY(), getZ()));
        this.setTransform(offset);
    }

    /**
     * @return the texto
     */
    public String getTexto() {
        return texto;
    }

    /**
     * @param texto the texto to set
     */
    public void setTexto(String texto) {
        this.texto = texto;
    }

    /**
     * @return the Fonte
     */
    public String getFonte() {
        return Fonte;
    }

    /**
     * @param Fonte the Fonte to set
     */
    public void setFonte(String Fonte) {
        this.Fonte = Fonte;
    }

    /**
     * @return the tamanho
     */
    public int getTamanho() {
        return tamanho;
    }

    public void mudarTamanho(int tamanho) {
        setTamanho(tamanho);
        this.removeAllChildren();

        // face it in the scene graph
        Transform3D rotation = new Transform3D();
        TransformGroup rotation_group = new TransformGroup(rotation);
        this.addChild(rotation_group);

        // make a texture mapped polygon
        texto2D = new Text2D(getTexto(), getCor(), getFonte(), getTamanho(), getArte());

        // set it to draw both the front and back of the poly
        PolygonAttributes msg_attributes = new PolygonAttributes();
        msg_attributes.setCullFace(PolygonAttributes.CULL_NONE);
        msg_attributes.setBackFaceNormalFlip(true);
        texto2D.getAppearance().setPolygonAttributes(msg_attributes);

        // attach it
        rotation_group.addChild(texto2D);
    }

    /**
     * @param tamanho the tamanho to set
     */
    public void setTamanho(int tamanho) {
        this.tamanho = tamanho;
    }

    /**
     * @return the cor
     */
    public Color3f getCor() {
        return cor;
    }

    /**
     * @param cor the cor to set
     */
    public void setCor(Color3f cor) {
        this.cor = cor;
    }

    /**
     * @return the arte
     */
    public int getArte() {
        return arte;
    }

    public void mudarArte(int stilo) {
        setArte(stilo);
        this.removeAllChildren();

        // face it in the scene graph
        Transform3D rotation = new Transform3D();
        TransformGroup rotation_group = new TransformGroup(rotation);
        this.addChild(rotation_group);

        // make a texture mapped polygon
        texto2D = new Text2D(getTexto(), getCor(), getFonte(), getTamanho(), getArte());

        // set it to draw both the front and back of the poly
        PolygonAttributes msg_attributes = new PolygonAttributes();
        msg_attributes.setCullFace(PolygonAttributes.CULL_NONE);
        msg_attributes.setBackFaceNormalFlip(true);
        texto2D.getAppearance().setPolygonAttributes(msg_attributes);

        // attach it
        rotation_group.addChild(texto2D);
    }

    /**
     * @param arte the arte to set
     */
    public void setArte(int arte) {
        this.arte = arte;
    }

    /**
     * @return the x
     */
    public float getX() {
        return x;
    }

    /**
     * @param x the x to set
     */
    public void setX(float x) {
        this.x = x;
    }

    /**
     * @return the y
     */
    public float getY() {
        return y;
    }

    /**
     * @param y the y to set
     */
    public void setY(float y) {
        this.y = y;
    }

    /**
     * @return the z
     */
    public float getZ() {
        return z;
    }

    /**
     * @param z the z to set
     */
    public void setZ(float z) {
        this.z = z;
    }
}

